package hotLeetcode;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class H139Leetcode  {
    public static boolean wordBreak(String s, List<String> wordDict) {



        HashSet<String> hashSet = new HashSet<>(wordDict);
        int n = s.length();
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        for (int i = 1; i <= n ; i++) {
            for (int j = 0; j < i; j++) {
                if (dp[j] && hashSet.contains(s.substring(j, i))) {
                    dp[i] = true;
                    break;

                }
            }

        }


        return dp[n];
    }

    public static void main(String[] args) {
        String s = "leetcode";
        List<String> wordDict = Arrays.asList("leet", "code");
        System.out.println(wordBreak(s, wordDict)); // 输出: true
    }
}
